<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;

class Admins extends Authenticatable
{
    use HasApiTokens,Notifiable;

    protected $table = 'admins';

    const STATUS_1 = 1;
    const STATUS_2 = 2;

    const STATUS_TEXT = [
        self::STATUS_1 => '<span class="el-tag">正常</span>',
        self::STATUS_2 => '<span class="el-tag el-tag--danger">锁定</span>',
    ];

    protected $fillable = [
        'id','username','nickname','password','created_at','status', 'login_at','login_ip','created_at','updated_at','nickname'
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $dates = ['login_at'];

    /**
     * passport默认使用email字段作为用户名，如果usename是其他字段必须重新定义findForPassport方法，
     * 且必须是public
     * @param $username
     * @return mixed
     */
    public function findForPassport($username)
    {
        return self::where('username', $username)->first();
    }

}
